home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvdraw / examples / datasource / varselectdlg.cpp < prev    next >
C/C++ Source or Header  |  1997-05-19  |  6KB  |  202 lines

  1. // VarSelectDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "VarSelectDlg.h"
  6. #include "DvDsDll.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14.  
  15. BOOL CVarSelectDlg::m_FirstTime = TRUE;
  16.  
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CVarSelectDlg dialog
  20.  
  21.  
  22. CVarSelectDlg::CVarSelectDlg(VARDEFDATA* pList, DV_DSDLLDATA* m_pData, CWnd* pParent /*=NULL*/)
  23. : CDialog(CVarSelectDlg::IDD, pParent), m_pVarDefList(pList),m_pData(m_pData),
  24.   m_pSelectedVarData(0)
  25. {
  26.     //{{AFX_DATA_INIT(CVarSelectDlg)
  27.     //}}AFX_DATA_INIT
  28. }
  29.  
  30.  
  31. void CVarSelectDlg::DoDataExchange(CDataExchange* pDX)
  32. {
  33.     CDialog::DoDataExchange(pDX);
  34.     //{{AFX_DATA_MAP(CVarSelectDlg)
  35.     DDX_Control(pDX, IDC_VARLIST, m_VarList);
  36.     //}}AFX_DATA_MAP
  37. }
  38.  
  39.  
  40. BEGIN_MESSAGE_MAP(CVarSelectDlg, CDialog)
  41.     //{{AFX_MSG_MAP(CVarSelectDlg)
  42.     ON_BN_CLICKED(IDC_STD_BROWSER, OnStdBrowser)
  43.     //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CVarSelectDlg message handlers
  48.  
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. //
  52. BOOL CVarSelectDlg::OnInitDialog() 
  53. {
  54.     CDialog::OnInitDialog();
  55.     
  56.     int            nIndex;
  57.     CString        colVal;
  58.     VARDEFDATA* pList;
  59.     CRect        r;
  60.  
  61.     m_VarList.GetClientRect(&r);
  62.     int width = r.right/10;
  63.   int nigglybits = r.right % 10;
  64.  
  65.     VERIFY(m_StdBrowser.AutoLoad(IDC_STD_BROWSER, this));
  66.  
  67.     m_VarList.InsertColumn(0,"Variable", LVCFMT_LEFT,   3*width);
  68.     m_VarList.InsertColumn(1,"Type",     LVCFMT_LEFT,   2*width,1);
  69.     m_VarList.InsertColumn(2,"Min",      LVCFMT_CENTER, width,2);
  70.     m_VarList.InsertColumn(3,"Max",      LVCFMT_CENTER, width,3);
  71.     m_VarList.InsertColumn(4,"Shape",    LVCFMT_LEFT,   (3*width+nigglybits),4);
  72.  
  73.     for(nIndex = 0,pList = m_pVarDefList;pList;pList = pList->next,nIndex++)
  74.     {
  75.         m_VarList.InsertItem(nIndex,(LPCTSTR)pList->m_csVarName.SpanExcluding(";"));
  76.         m_VarList.SetItemData(nIndex, (DWORD)pList);
  77.  
  78.         m_VarList.SetItemText(nIndex, 1, (LPCTSTR)pList->m_csVarTypeName);
  79.  
  80.         colVal.Format("%.3g",pList->m_dLowRange);
  81.         m_VarList.SetItemText(nIndex, 2, (LPCTSTR)colVal);
  82.         colVal.Format("%.3g",pList->m_dHighRange);
  83.         m_VarList.SetItemText(nIndex, 3, (LPCTSTR)colVal);
  84.  
  85.         // Determine something useful to say about the variables shape...
  86.         if(pList->m_nCols == 1)
  87.         {
  88.             if(pList->m_nRows == 1)
  89.                 colVal = "SCALAR";
  90.             else
  91.                 colVal.Format("COL. VECTOR[%d][%d]",pList->m_nRows,pList->m_nCols);
  92.         }
  93.         else if(pList->m_nRows == 1)
  94.             colVal.Format("ROW VECTOR[%d][%d]",pList->m_nRows,pList->m_nCols);
  95.         else
  96.             colVal.Format("MATRIX[%d][%d]",pList->m_nRows,pList->m_nCols);
  97.  
  98.         m_VarList.SetItemText(nIndex, 4, (LPCTSTR)colVal);
  99.     }
  100.  
  101.     // Just a little cutsie example of how a data source DLL can discriminate
  102.     // accurately the various contexts from which it is being called from within
  103.     // the core of DV-Draw...
  104.  
  105.     CString context;
  106.  
  107.     if(m_pData->m_Context & DV_DSDLL_SELECTDATA)
  108.         context = "Select new variable for ";
  109.     else
  110.         context = "Changing variable in ";
  111.  
  112.     if(m_pData->m_Context & DV_DSDLL_EDITDYNAMICS)
  113.         context += "DYNAMICS";
  114.     else if(m_pData->m_Context & DV_DSDLL_EDITGRAPH)
  115.         context += "GRAPH";
  116.     else if(m_pData->m_Context & DV_DSDLL_EDITINPUT)
  117.         context += "INPUT OBJECT";
  118.     else
  119.         context += "!!! UNKNOWN !!!";
  120.  
  121.     SetWindowText((LPCTSTR)context);
  122.  
  123.     return TRUE;  // return TRUE unless you set the focus to a control
  124.                   // EXCEPTION: OCX Property Pages should return FALSE
  125. }
  126.  
  127.  
  128. /////////////////////////////////////////////////////////////////////////////
  129. //
  130. //  Called by the list conrol, which does hit testing for us...
  131. //
  132. void CVarSelectDlg::SelectItem(int nItem)
  133. {
  134.     m_pSelectedVarData = (VARDEFDATA*)m_VarList.GetItemData(nItem);
  135. }
  136.  
  137.  
  138. /////////////////////////////////////////////////////////////////////////////
  139. //
  140. void CVarSelectDlg::OnStdBrowser() 
  141. {
  142.     CDvDsDll* pDsDll;
  143.  
  144.     DVIGetInterface(IID_DV_Datasource, (void**)&pDsDll);
  145.  
  146.   if(!pDsDll)
  147.   {
  148.     AfxMessageBox("Unable to load standard DataViews Data Browser!");
  149.     return;
  150.   }
  151.  
  152.   if(m_FirstTime)
  153.   {
  154.     // Our data browser does not work with the view directly, so there are
  155.     // no default datasources created when the view is initialized.  For 
  156.     // our purposes here as an example, if its the first time, we'll ask the
  157.     // standard data browser to init the view; that way there will be some-
  158.     // thing to see (otherwise its an empty datasource list).
  159.     int real_context = m_pData->m_Context;
  160.  
  161.     m_pData->m_Context = DV_DSDLL_INITNEWVIEW;
  162.     pDsDll->HandleRequest(m_pData,this);
  163.     m_pData->m_Context = real_context;
  164.  
  165.     m_FirstTime = FALSE;
  166.   }
  167.  
  168.     if(((pDsDll->HandleRequest(m_pData,this)) == IDOK) )
  169.   {
  170.     // User has selected OK button, so we could do some application
  171.     // specific things at this point.  The assignment below is merely
  172.     // a convenient place for stopping the debugger so you can see what
  173.     // is happening.
  174.       DSVAR newDsvar = m_pData->m_DsVar;
  175.     }
  176. }
  177.  
  178.  
  179. /////////////////////////////////////////////////////////////////////////////
  180. //
  181. void CVarSelectDlg::OnOK() 
  182. {
  183.     // Is variable selection required?
  184.     BOOL needVAR = (BOOL)((m_pData->m_Context & DV_DSDLL_SELECTDATA) || 
  185.                             (m_pData->m_Context & DV_DSDLL_EXCHANGEDATA) );
  186.  
  187.     if(!needVAR || (needVAR && m_pSelectedVarData))
  188.         CDialog::OnOK();
  189.     else
  190.         Beep(300,150);
  191. }
  192.  
  193.  
  194. /////////////////////////////////////////////////////////////////////////////
  195. //
  196. void CVarSelectDlg::OnCancel() 
  197. {
  198.     m_pSelectedVarData = 0;
  199.     CDialog::OnCancel();
  200. }
  201.  
  202.